package com.purchase.common.utils.uuid;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;

/**
 * ID生成器工具类
 *
 * @author purchase
 */
public class IdUtils {

    private static SimpleDateFormat format = new SimpleDateFormat("yyMMddHHMMss");
    private static SimpleDateFormat format1 = new SimpleDateFormat("yyMMdd");
    private static Random random = new Random();

    /**
     * 获取随机UUID
     *
     * @return 随机UUID
     */
    public static String randomUUID() {
        return UUID.randomUUID().toString();
    }

    /**
     * 简化的UUID，去掉了横线
     *
     * @return 简化的UUID，去掉了横线
     */
    public static String simpleUUID() {
        return UUID.randomUUID().toString(true);
    }

    /**
     * 获取随机UUID，使用性能更好的ThreadLocalRandom生成UUID
     *
     * @return 随机UUID
     */
    public static String fastUUID() {
        return UUID.fastUUID().toString();
    }

    /**
     * 简化的UUID，去掉了横线，使用性能更好的ThreadLocalRandom生成UUID
     *
     * @return 简化的UUID，去掉了横线
     */
    public static String fastSimpleUUID() {
        return UUID.fastUUID().toString(true);
    }

    public static long randomSnowflake() {
        long code = Long.parseLong(format1.format(Calendar.getInstance().getTime()) + random.nextInt(99999999));
        return code;
    }
}
